//
//  CustomTableViewCell.m
//  哎游
//
//  Created by 康守帅 on 15-1-4.
//  Copyright (c) 2015年 lanou3g.com 蓝鸥科技. All rights reserved.
//

#import "TravelsListTableViewCell.h"
#import "macro.h"
#import "Masonry.h"

@implementation TravelsListTableViewCell

- (void)dealloc
{
    [_backImageView release];
    [_title release];
    [_date release];
    [_dateNum release];
    [_visits release];
    [_userImageView release];
    [_userName release];
    [super dealloc];
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        self.backImageView = [[UIImageView alloc] init];
        [self addSubview:_backImageView];

        if (IOS_VERSION >= 7.0) {
            [_backImageView mas_makeConstraints:^(MASConstraintMaker *make) {
                make.top.mas_equalTo(super.mas_top).offset(10);
                make.height.mas_equalTo(220);
                make.left.equalTo(super.mas_left).offset(10);
                make.right.equalTo(super.mas_right).offset(-10);
            }];
            
            UIView *maskView = [[UIView alloc] init];
            maskView.backgroundColor = [UIColor blackColor];
            maskView.alpha = 0.2;
            [_backImageView addSubview:maskView];
                    [maskView mas_makeConstraints:^(MASConstraintMaker *make) {
                        make.top.left.bottom.and.right.equalTo(_backImageView).with.insets(UIEdgeInsetsMake(0, 0, 0, 0));
                    }];
            [maskView release];
        }else {
            _backImageView.frame = CGRectMake(10, 0, self.contentView.frame.size.width - 20, 220);
            
            UIView *maskView = [[UIView alloc] initWithFrame:CGRectMake(10, 0, self.contentView.frame.size.width - 20, 220)];
            maskView.backgroundColor = [UIColor blackColor];
            maskView.alpha = 0.2;
            [_backImageView addSubview:maskView];
            [maskView release];
        }

        _backImageView.layer.masksToBounds = YES;
        _backImageView.layer.cornerRadius = 10;
//        _backImageView.layer.borderWidth = 1;
        [_backImageView release];
        
        self.title = [[UILabel alloc] init];
        _title.font = [UIFont boldSystemFontOfSize:20];
        _title.textColor = [UIColor whiteColor];
        _title.backgroundColor = [UIColor clearColor];
        [_backImageView addSubview:_title];
        [_title mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(_backImageView.mas_left).offset(10);
            make.top.equalTo(_backImageView.mas_top).offset(15);
            make.right.equalTo(_backImageView.mas_right).offset(-10);
        }];
        [_title release];
        
        self.date = [[UILabel alloc] init];
        _date.font = [UIFont boldSystemFontOfSize:10];
        _date.textColor = [UIColor whiteColor];
        _date.backgroundColor = [UIColor clearColor];
        [_backImageView addSubview:_date];
        [_date mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(_title.mas_bottom).offset(10);
            make.left.equalTo(_backImageView.mas_left).offset(15);
            make.width.mas_equalTo(55);
        }];
        [_date release];
        
        self.dateNum = [[UILabel alloc] init];
        _dateNum.font = [UIFont boldSystemFontOfSize:10];
        _dateNum.textColor = [UIColor whiteColor];
        _dateNum.backgroundColor = [UIColor clearColor];
        [_backImageView addSubview:_dateNum];
        [_dateNum mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(_title.mas_bottom).offset(10);
            make.left.equalTo(_date.mas_right).offset(5);
            make.width.mas_equalTo(10);
        }];
        [_dateNum release];
        
        UILabel *aLabel = [[UILabel alloc] init];
        aLabel.text = @"天";
        aLabel.font = [UIFont boldSystemFontOfSize:10];
        aLabel.textColor = [UIColor whiteColor];
        aLabel.backgroundColor = [UIColor clearColor];
        [_backImageView addSubview:aLabel];
        [aLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(_title.mas_bottom).offset(10);
            make.left.equalTo(_dateNum.mas_right).offset(0);
            make.width.mas_equalTo(10);
        }];
        [aLabel release];
        
        self.visits = [[UILabel alloc] init];
        _visits.font = [UIFont boldSystemFontOfSize:10];
        _visits.textColor = [UIColor whiteColor];
        _visits.backgroundColor = [UIColor clearColor];
        [_backImageView addSubview:_visits];
        [_visits mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(_title.mas_bottom).offset(10);
            make.left.equalTo(aLabel.mas_right).offset(10);
            make.width.mas_equalTo(30);
        }];
        [_visits release];
        
        UILabel *bLabel = [[UILabel alloc] init];
        bLabel.text = @"次浏览";
        bLabel.font = [UIFont boldSystemFontOfSize:10];
        bLabel.backgroundColor = [UIColor clearColor];
        bLabel.textColor = [UIColor whiteColor];
        [_backImageView addSubview:bLabel];
        [bLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(_title.mas_bottom).offset(10);
            make.left.equalTo(_visits.mas_right).offset(0);
            make.width.mas_equalTo(30);
        }];
        [bLabel release];
        
        self.address = [[UILabel alloc] init];
        _address.font = [UIFont systemFontOfSize:10];
        _address.textColor = [UIColor whiteColor];
        _address.backgroundColor = [UIColor clearColor];
        [_backImageView addSubview:_address];
        [_address mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(_date.mas_bottom).offset(5);
            make.left.equalTo(_backImageView.mas_left).offset(15);
            make.right.equalTo(_backImageView.mas_right).offset(-15);
        }];
        [_address release];
        
        self.userImageView = [[UIImageView alloc] init];
        _userImageView.layer.masksToBounds = YES;
        _userImageView.backgroundColor = [UIColor clearColor];
        [_backImageView addSubview:_userImageView];
        [_userImageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(_backImageView.mas_left).offset(15);
            make.bottom.equalTo(_backImageView.mas_bottom).offset(-20);
            make.width.mas_equalTo(20);
            make.height.mas_equalTo(20);
        }];
        
        _userImageView.layer.cornerRadius = 10.0;
        _userImageView.layer.borderWidth = 0;
        [_userImageView release];
        
        self.userName = [[UILabel alloc] initWithFrame:CGRectMake(40, _backImageView.frame.size.height / 5 * 4 + 5, 80, 10)];
        _userName.font = [UIFont systemFontOfSize:10];
        _userName.backgroundColor = [UIColor clearColor];
        _userName.textColor = [UIColor whiteColor];
        [_backImageView addSubview:_userName];
        [_userName mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.equalTo(_backImageView.mas_bottom).offset(-23);
            make.left.equalTo(_userImageView.mas_right).offset(5);
            make.right.equalTo(_backImageView.mas_right).offset(-10);
        }];
        [_userName release];
    }
    return self;
}



- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
